layui.define( function (exports) {
    var obj = {
        include_js(file, target) {
            return new Promise((resolve, reject)=>{
                var js;
                if (target == undefined) {
                    target = self;
                }
                var html_doc = target.document.getElementsByTagName('head')[0];
                js = target.document.createElement("script");
                js.setAttribute("type", 'text/javascript')
                js.setAttribute('src', file);
                html_doc.appendChild(js);
                if (!/*@cc_on!@*/0) { //if not IE
                    js.onload=function () {
                        resolve(axios);
                    };
                    js.onerror=function () {
                        reject('文件加载失败');
                    }
                    js.onabort=function (){
                        reject('文件加载被取消');
                    }
                } else {
                    //IE6、IE7 support js.onreadystatechange
                    js.onreadystatechange = function () {
                        if (js.readyState == 'loaded' || js.readyState == 'complete') {
                            resolve(axios);
                        }
                    }
                }
            })
        },
         generateUUID() {
             var d = new Date().getTime();
             if (window.performance && typeof window.performance.now === "function") {
                 d += performance.now(); //use high-precision timer if available
             }
             var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                 var r = (d + Math.random() * 16) % 16 | 0;
                 d = Math.floor(d / 16);
                 return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
             });
             return uuid;
         },
        getByteLength(str) {
            var length = 0;
            var reg = /[\u4e00-\u9fa5]/;
            for (var i = 0; i < str.length; i++) {
                if (reg.test(str.charAt(i))) {
                    length += 2;
                } else {
                    length++;
                }
            }
            return length;
        }
    }
    //输出 mymod 接口
    exports('common', obj);
});